package com.example.gui;

import com.example.dao.AdminDAO;
import com.example.model.CardInfo;
import com.example.model.UserInfo;

import javax.swing.*;
import java.awt.*;
import java.util.List;

public class AdminMainFrame extends JFrame {

    public AdminMainFrame() {
        setTitle("银行管理系统 - 管理员面板");
        setSize(1000, 700);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);

        // 使用卡片布局实现功能切换
        CardLayout cardLayout = new CardLayout();
        JPanel mainPanel = new JPanel(cardLayout);

        // 创建功能按钮面板
        JPanel menuPanel = new JPanel(new GridLayout(0, 1, 10, 10));
        menuPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        menuPanel.setPreferredSize(new Dimension(200, getHeight()));

        // 按钮样式设置
        Font buttonFont = new Font("微软雅黑", Font.BOLD, 16);

        // 客户管理按钮
        JButton customerBtn = createMenuButton("客户管理", buttonFont);
        customerBtn.addActionListener(e -> cardLayout.show(mainPanel, "customer"));

        // 银行卡管理按钮
        JButton cardBtn = createMenuButton("银行卡管理", buttonFont);
        cardBtn.addActionListener(e -> cardLayout.show(mainPanel, "card"));

        // 存款管理按钮
        JButton depositBtn = createMenuButton("存款管理", buttonFont);
        depositBtn.addActionListener(e -> cardLayout.show(mainPanel, "deposit"));

        // 交易管理按钮
        JButton tradeBtn = createMenuButton("交易管理", buttonFont);
        tradeBtn.addActionListener(e -> cardLayout.show(mainPanel, "trade"));

        // 退出登录按钮
        JButton logoutBtn = createMenuButton("退出登录", buttonFont);
        logoutBtn.addActionListener(e -> {
            new StartFrame().setVisible(true);
            dispose();
        });

        // 添加按钮到菜单面板
        menuPanel.add(customerBtn);
        menuPanel.add(cardBtn);
        menuPanel.add(depositBtn);
        menuPanel.add(tradeBtn);
        menuPanel.add(Box.createVerticalGlue()); // 填充空白区域
        menuPanel.add(logoutBtn);

        // 添加各功能界面到主面板
        mainPanel.add(new CustomerManagementPanel(), "customer");
        mainPanel.add(new CardManagementPanel(), "card");
        mainPanel.add(new DepositManagementPanel(), "deposit");
        mainPanel.add(new TransactionManagementPanel(), "trade");

        // 默认显示客户管理
        cardLayout.show(mainPanel, "customer");

        // 设置界面布局
        JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, menuPanel, mainPanel);
        splitPane.setDividerLocation(200);
        splitPane.setDividerSize(3);
        splitPane.setEnabled(false); // 禁止调整分隔线

        add(splitPane);
    }

    // 创建统一风格的菜单按钮
    private JButton createMenuButton(String text, Font font) {
        JButton button = new JButton(text);
        button.setFont(font);
        button.setFocusPainted(false);
        button.setBackground(new Color(70, 130, 180)); // 钢蓝色
        button.setForeground(Color.WHITE);
        button.setBorder(BorderFactory.createEmptyBorder(10, 15, 10, 15));
        button.setAlignmentX(Component.CENTER_ALIGNMENT);
        return button;
    }
}